package com.neusoft.elmboot.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Insert;


import com.neusoft.elmboot.po.Business;

@Mapper
public interface BusinessMapper {

	@Select("select * from business where orderTypeId=#{orderTypeId} order by businessId")
	public List<Business> listBusinessByOrderTypeId(Integer orderTypeId);

	@Select("select *  from business where businessId=#{businessId} and password=#{password}")
	public Business getBusinessByIdByPass(Integer businessId, String password);
	
	@Select("select * from business where businessId=#{businessId}")
	public Business getBusinessById(Integer businessId);

	@Insert("insert into business values(#{businessId},#{businessName},#{businessAddress},#{businessExplain},null,#{orderTypeId},#{starPrice},#{deliveryPrice},#{remarks},#{password})")
	public int saveBusiness(Business business);
	
	
	@Update("update business set businessName=#{businessName},businessAddress=#{businessAddress},businessExplain=#{businessExplain},orderTypeId=#{orderTypeId},starPrice=#{starPrice},deliveryPrice=#{deliveryPrice}, remarks=#{remarks}, password=#{password} where businessId=#{businessId}")
	public int updateBusiness(Business business);

	// 新增方法：根据 orderTypeId 随机获取指定数量的商家
	@Select("select * from business where orderTypeId=#{orderTypeId} order by RAND() limit #{limit}")
	public List<Business> listRandomBusinessesByOrderTypeId(@Param("orderTypeId") Integer orderTypeId, @Param("limit") Integer limit);


	@Select("SELECT * FROM business WHERE businessName LIKE #{name}")
    List<Business> findBusinessByName(@Param("name") String name);
	@Update("update business set password = #{newPass} where businessId = #{businessId} and password = #{oldPass}")
    public int updateBusinessPassword(Integer businessId, String oldPass, String newPass);
}
